define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'outside/index' + location.search,
                    add_url: 'outside/add',
                    edit_url: 'outside/edit',
                    del_url: 'outside/del',
                    multi_url: 'outside/multi',
                    table: 'outside',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'phone', title: __('Phone')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        ana: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'outside/ana' + location.search,
                    add_url: 'outside/add',
                    edit_url: 'outside/edit',
                    del_url: 'outside/del',
                    multi_url: 'outside/multi',
                    table: 'outside',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                showExport: true,
                showToggle: false,
                showColumns: false,
                commonSearch: true,
                searchFormVisible: true,
                searchFormTemplate: 'searchformtpl',
                queryParams: function (params) {
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    if($("#college_id").val()){
                        filter.college_id = $("#college_id").val();
                        op.college_id = "=";
                    }

                    if($("#department_id").val()){
                        filter.department_id = $("#department_id").val();
                        op.department_id = "=";
                    }

                    //if($("#is_reported").val()){
                    filter.create_time = $("#create_time").val();
                    op.create_time = "between";
                    //}

                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },
                columns: [
                    [
                        {field: '', title: __('序号'),operate:false,table:table,formatter: Table.api.formatter.natureorder},
                        {field: 'nickname', title: __('Name')},
                        {field: 'tel', title: __('Phone')},
                        {field: 'college_name', title: __('单位')},
                        {field: 'department_name', title: __('科室')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});